package cn.wolfcode.interceptor;

import cn.wolfcode.domain.Employee;
import cn.wolfcode.util.UserContext;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 登入拦截器
 * @Author: 伍家钰
 * @Date: 2020/7/12 21:16
 * @Version: 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断是否登入
        // Employee employee = UserContext.getCurrentUser();
        Employee employee = UserContext.getEmployee();
        if (employee == null) {
            //返回登入界面
            response.sendRedirect("/login.html");
            return false;
        }
        //登入成功,放行
        return true;
    }
}
